package src

type TimeCell struct {
	TaskHead *Task
}

type TimeCycle struct {
	Times    [60]*TimeCell
	curIndex int
}

func (t *TimeCycle) InsertTask(task *Task, index int) {
	if t.Times[index] == nil {
		cell := new(TimeCell)
		cell.TaskHead = task
		t.Times[index] = cell
	} else {
		oldHead := t.Times[index].TaskHead
		task.next = oldHead
		t.Times[index].TaskHead = task
	}
}

func (t *TimeCycle) GetTask() (*Task, bool) {
	t.curIndex += 1
	var taskHead *Task
	full := false
	if t.curIndex == 60 {
		t.curIndex = 0
		full = true
	}
	if t.Times[t.curIndex] != nil && t.Times[t.curIndex].TaskHead != nil {
		taskHead = t.Times[t.curIndex].TaskHead
		t.Times[t.curIndex].TaskHead = nil
	}
	return taskHead, full
}
